package ai.people.core.security.support;

import ai.people.core.security.entity.AuthenticationUser;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

/**
 * 登录用户参数解析器
 *
 * @author yuanqinglong
 * @date 2022/2/14 17:45
 */
public class LoginUserArgumentResolver implements HandlerMethodArgumentResolver {



    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        boolean assignable = parameter.getParameterType().isAssignableFrom(AuthenticationUser.class);
        return assignable;
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        return RequestHolderUtil.loginUser();
    }
}
